import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;

public class Test8 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<ShangPing> list = new ArrayList<>();
        ShangPing shangPing1 = new ShangPing("鸭蛋",10);
        ShangPing shangPing2 = new ShangPing("摇头风扇",2);
        ShangPing shangPing3 = new ShangPing("瓢虫项链",5);
        list.add(shangPing1);
        list.add(shangPing2);
        list.add(shangPing3);


        LocalTime now = LocalTime.now();
        String ya = "14:00:00";
        String ya1 = "23:30:00";
        String fen = "16:00:00";
        String fen1 = "18:00:00";
        String lian1 = "20:00:00";
        DateTimeFormatter df = DateTimeFormatter.ofPattern("HH:mm:ss");
        LocalTime date = LocalTime.parse(ya,df);
        LocalTime date1 = LocalTime.parse(ya1,df);
        LocalTime date2 = LocalTime.parse(fen,df);
        LocalTime date3 = LocalTime.parse(fen1,df);
        LocalTime date4 = LocalTime.parse(lian1,df);

        while (true) {
            System.out.println("JD秒杀活动开始了.....");
            System.out.println("商品序号1：Goods{商品名称=鸭蛋 ");
            System.out.println("商品序号2：Goods{商品名称=摇头风扇 ");
            System.out.println("商品序号3：Goods{商品名称=瓢虫项链 " );
            String ms = sc.next();

            switch (ms){
                case "鸭蛋":
                    if (now.isAfter(date)&&now.isBefore(date1)){
                        if(list.get(0).getSu()!=0){
                            System.out.println("库存鸭蛋还剩："+list.get(0).getSu()+"个");
                        }else {
                            System.out.println("鸭蛋已经抢购完毕，请选择别的商品吧");
                            break;
                        }

                        while (true) {
                            System.out.println("请您输入您要抢购的数量");
                            int n = sc.nextInt();
                            if (n>list.get(0).getSu()){
                                System.out.println("您抢购的数量超过库存，请您重新输入");
                            }else {
                                System.out.println("恭喜您抢购成功");
                                list.get(0).setSu(list.get(0).getSu()-n);
                                break;
                            }
                        }
                    }else {
                        break;
                    }
                    System.out.println("还需继续抢购按y，不抢购按x退出");
                    String n1 = sc.next();

                    switch (n1) {
                        case "y":
                            break;

                        case "x":
                            return;
                    }

                case "摇头风扇":
                    if (now.isAfter(date2)&&now.isBefore(date3)){
                        if (list.get(1).getSu()!=0){
                            System.out.println("库存风扇还剩："+list.get(1).getSu()+"个");
                        }else {
                            System.out.println("风扇已经抢购完毕，请选择别的商品吧");
                            break;
                        }

                        while (true) {
                            System.out.println("请您输入您要抢购的数量");
                            int n = sc.nextInt();
                            if (n>list.get(1).getSu()){
                                System.out.println("您抢购的数量超过库存，请您重新输入");
                            }else {
                                System.out.println("恭喜您抢购成功");
                                list.get(1).setSu(list.get(1).getSu()-n);
                                break;
                            }
                        }

                    }else {
                        break;
                    }
                    System.out.println("还需继续抢购按y，不抢购按x退出");
                    String n2 = sc.next();

                    switch (n2) {
                        case "y":
                            break;

                        case "x":
                            return;
                    }

                case "瓢虫项链":
                    if (now.isAfter(date3)&&now.isBefore(date4)){
                        if (list.get(2).getSu()!=0){
                            System.out.println("库存项链还剩："+list.get(2).getSu()+"个");
                        }else {
                            System.out.println("项链已经抢购完毕，请选择别的商品吧");
                        }

                        while (true) {
                            System.out.println("请您输入您要抢购的数量");
                            int n = sc.nextInt();
                            if (n>list.get(2).getSu()){
                                System.out.println("您抢购的数量超过库存，请您重新输入");
                            }else {
                                System.out.println("恭喜您抢购成功");
                                list.get(2).setSu(list.get(2).getSu()-n);
                                break;
                            }
                        }

                    }else {
                        break;
                    }
                    System.out.println("还需继续抢购按y，不抢购按x退出");
                    String n3 = sc.next();

                    switch (n3) {
                        case "y":
                            break;

                        case "x":
                            return;
                    }


            }
        }


    }
}
